/*
 * Copyright 2011 Thomas Golden
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.j2bugzilla.base;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * This class encapsulates all information about a point in the history of a single bug report posted on a Bugzilla
 * installation -- that is, when the changes were made, who made the changes, and what changed.
 * Each HistoryElement has one user, and one time, but has a set of one or more changes made at the time.
 * 
 * @author Tristan
 *
 */
public class HistoryElement
{
	/**
	 * The {@Code Change} class represents an individual change that occurred at this time, effected by the given user.
	 * Each Change happens on one field, and has zero or more Added or Removed items.
	 * For fields such as "status", which are simply a single value, the "added" field represents its new value,
	 * and the "removed" field represents its previous value.
	 * @author Tristan
	 *
	 */	
	public static class Change
	{
		
		private final String fieldName, added, removed;
		
		public Change(String fieldName, String added, String removed)
		{
			this.fieldName = fieldName;
			this.added = added;
			this.removed = removed;
		}
		
		public String fieldName(){return this.fieldName;}
		
		public String added() {return this.added;}
		
		public String removed(){return this.removed;}
		
		
	}
	
	private String user;
	private Date changeTime;
	//private final SimpleDateFormat bzDateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
	private Set<Change> changes;
	
	public HistoryElement(String user, Date changeTime, Set<Change> changes) throws ParseException
	{
		this.user = user;
		this.changeTime = changeTime;
		this.changes = changes;
	}
	
	//I don't think this would have been the best way to do it anymore.
	//The GetHistory class will just pass in an array of Changes to HistoryElement.
	/*public void addChange(String fieldName, String added, String removed)
	{
		Change ch = new Change(fieldName, added, removed);
		changes.add(ch);
	}*/

	public String getUser() {
		return user;
	}

	public Date getChangeTime() {
		return changeTime;
	}
	
	public Set<Change> getChanges()
	{
		return changes;
	}
}